const getApps = getApp().globalData
const util = require('../../utils/util.js')
const Monitor = require('../../utils/monitor.js').Monitor
Page(Monitor.hookApp({
  data: {
    imgUrl: getApps.imgUrl,
    imgUrls: getApps.imgUrls,
    img: `${getApp().globalData.imgUrl}jsy-newshop搜索图标.svg`,
    showList: [],
    leftList: [{
      type_name: "全部",
      type_id: 0,
      type_cover: `jsynewshop全部商品.svg`
    }]
  },
  //左侧导航栏点击事件
  click(e) {
    var e = e.currentTarget.dataset.current
    var list = this.data.responseList
    if (this.data.currentTab == e) {} else { 
      if (e == 0) {
        wx.navigateTo({
          url: '/pages/ShopList/ShopList?title=全部商品',
        })
      } else {
        this.setData({
          currentTab: e
        })
        this.rightList(e)
      }

    }
  },
  onLoad: function(options) {
    this.leftList(options.type_id);
  },
  leftList(type_id) { //请求左边列表
    util.API('spwx/v1.Shop/one_two_classification', {
      type_id: 0,
    }).then(res => {
      var leftList = this.data.leftList.concat(res.data.list)
     
      console.log(leftList)
      this.setData({
        currentTab: type_id ? type_id : leftList[1].type_id,
        leftList,
        isshowtwo: res.data.isshowtwo
      })
      this.rightList(this.data.currentTab)
    })
  },
  rightList(currentTab) { //请求右边列表
    util.API('spwx/v1.Shop/one_two_classification', {
      type_id: currentTab,

    }).then(
      res => {
        let {
          code,
          data
        } = res
        if (code === 200) {
          this.setData({
            showList: data.list
          })
        }else{
          this.setData({
            showList: data
          })
        }
      }
    )
  }
}))